/**
 * Detail Dialog Box<!-- 详情对话框 -->
 */
var BasicGoodsInfoDlg = {
    data: {
        goodsCustomerId: "",
        goodsCustomerName: "",
        goodsName: "",
        goodsNumber: "",
        goodsHelpcode: "",
        goodsUnit: "",
        goodsHeavybubble: "",
        goodsPacking: "",
        goodsBigtype: "",
        goodsType: "",
        goodsCondition: "",
        goodsBaleunit: "",
        goodsBalespecs: "",
        goodsWeight: "",
        goodsWeightunit: "",
        goodsBottom: "",
        goodsLamination: "",
        goodsTraylayer: "",
        length: "",
        width: "",
        height: "",
        goodsVolume: "",
        goodsCharging: "",
        goodsEnterreference: "",
        goodsOutreference: "",
        goodsInnercode: "",
        goodsWhethercode: "",
        goodsSpecs: "",
        goodsBrand: "",
        goodsPlaceoforigin: "",
        goodsManufactor: "",
        goodsMinimumstock: "",
        goodsStocklimit: "",
        goodsWarranty: "",
        goodsWarrantycycle: "",
        goodsResidencetlme: "",
        goodsSupportvolume: "",
        goodsUnivalent: "",
        goodsNodes: "",
        version: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate  = layui.laydate;

    //Adjust current iframe pop-up height<!-- 让当前iframe弹层高度适应 -->
    admin.iframeAuto();

    /*//渲染时间
    laydate.render({
        elem: '#goodsWarranty' //保质期
    });*/

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/basicGoods/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('basicGoodsForm', result.data);

    //Form submission event<!-- 表单提交事件 -->
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/basicGoods/editItem", function (data) {
        	if (data.success) {
                Feng.success("Update successful!"); // Update successful<!-- 更新成功！ -->
            	window.location.href = Feng.ctxPath + '/basicGoods'
			} else {
                Feng.error("Update failed! "+data.message); // Update failed<!-- 更新失败！ -->
			}
        }, function (data) {
            Feng.error("Update failed! " + data.responseJSON.message); // Update failed<!-- 更新失败！ -->
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //When inputting length<!-- 输入长时 -->
    $("#length").keyup(function () {
        var length = $("#length").val();//Input length<!-- 应入长 -->
        var width = $("#width").val();//Width<!-- 宽 -->
        var height = $("#height").val();//Height<!-- 高 -->
		if(!isNaN(length) && length != "" && parseFloat(length) > 0){
			if(!isNaN(width) && width != "" && parseFloat(width) > 0){
				if(!isNaN(height) && height != "" && parseFloat(height) > 0){
	        		$("#goodsVolume").val(length * width * height);//Change volume<!-- 改变体积 -->
				}
			}
		}
    });

    //When inputting width<!-- 输入宽时 -->
    $("#width").keyup(function () {
        var width = $("#width").val();//Width<!-- 宽 -->
        var length = $("#length").val();//Input length<!-- 应入长 -->
        var height = $("#height").val();//Height<!-- 高 -->
		if(!isNaN(width) && width != "" && parseFloat(width) > 0){
			if(!isNaN(length) && length != "" && parseFloat(length) > 0){
				if(!isNaN(height) && height != "" && parseFloat(height) > 0){
	        		$("#goodsVolume").val(length * width * height);//Change volume<!-- 改变体积 -->
				}
			}
		}
    });

    //When inputting height<!-- 输入高时 -->
    $("#height").keyup(function () {
        var height = $("#height").val();//Height<!-- 高 -->
        var width = $("#width").val();//Width<!-- 宽 -->
        var length = $("#length").val();//Input length<!-- 应入长 -->
		if(!isNaN(height) && height != "" && parseFloat(height) > 0){
			if(!isNaN(width) && width != "" && parseFloat(width) > 0){
				if(!isNaN(length) && length != "" && parseFloat(length) > 0){
	        		$("#goodsVolume").val(length * width * height);//Change volume<!-- 改变体积 -->
				}
			}
		}
    });

    //When inputting bottom<!-- 输入底时 -->
    $("#goodsBottom").keyup(function () {
        var goodsBottom = $("#goodsBottom").val();//Bottom<!-- 底 -->
        var goodsLamination = $("#goodsLamination").val();//Layers<!-- 叠层 -->
		if(!isNaN(goodsBottom) && goodsBottom != "" && parseFloat(goodsBottom) > 0){
			if(!isNaN(goodsLamination) && goodsLamination != "" && parseFloat(goodsLamination) > 0){
        		$("#goodsSupportvolume").val(goodsBottom * goodsLamination);//Change quantity per pallet<!-- 改变每托存量 -->
			}
		}
    });

    //When inputting layers<!-- 输入叠层 -->
    $("#goodsLamination").keyup(function () {
        var goodsLamination = $("#goodsLamination").val();//Layers<!-- 叠层 -->
        var goodsBottom = $("#goodsBottom").val();//Bottom<!-- 底 -->
		if(!isNaN(goodsLamination) && goodsLamination != "" && parseFloat(goodsLamination) > 0){
			if(!isNaN(goodsBottom) && goodsBottom != "" && parseFloat(goodsBottom) > 0){
        		$("#goodsSupportvolume").val(goodsBottom * goodsLamination);//Change quantity per pallet<!-- 改变每托存量 -->
			}
		}
    });

    //Back button<!-- 返回按钮 -->
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/basicGoods'
    });

    //Query product category<!-- 查询商品类别 -->
    form.on('select(goodsBigtype)',function(){
    	$("#goodsType").empty();
    	$.ajax({
    		url:Feng.ctxPath + '/storageStock/queryGoodsType',
    	    dataType:"json",   //返回格式为json
    	    async: false,
    	    data:{"dictcode":$("#goodsBigtype").find("option:checked").attr("id"),"code":"COMMODITY_CATEGORY"},    //参数值
    	    type:"post",   //请求方式
    	    success:function(data){
    	        if(data.length>0){
    	        	var str = "<option value=''>请选择</option>";
    	        	$.each(data,function(key,value){
    	        		str += "<option value='"+value.name+"'>"+value.name+"</option>";
    	        	});
    	        	$("#goodsType").html(str);
    	        }
    	    }
    	});
        form.render('select');
    });

});
